//LiuZh 2017-06-22

import React, {Component} from 'react';
import {
    View,
    Text,
    Button,
    StyleSheet,
} from 'react-native';

//导入SN用作顶部back等的导航

import {
    StackNavigator,

} from 'react-navigation';

//主界面
import RegisterScene from '../../../core/scene/page.register';
import InitDB from '../../../core/database/init-db';
import HomeScene from './../scene/HomeScene';
import LoginScene from '../../../core/scene/page.login';
import AboutUsScene from '../../../core/scene/page.about-us';
import ResetPwdScene from '../../../core/scene/page.reset-pwd';
import VideoScene from '../scene/VideoScene';
import ForgetPwdScene from '../../../core/scene/page.forget-password';
import UserInfoScene from '../../../core/scene/page.user-info';
import Toolbar from '../../../core/component/comp.toolbar';

let backImgSrc = require('../../../img/back.png');

/*初始化数据库 */
InitDB.init();


let currentUser = InitDB.getCurrentUser();

//alert(currentUser);

let initialRouteName;

if (currentUser) {//跳转到主页
    //  alert("current:"+ InitDB.getCurrentUser().FIRST_OPEN_TIME);
// if(true){
    initialRouteName = 'Home';
} else {
    initialRouteName = 'Login';
}

//ToastUtil.show("initialRouteName:"+initialRouteName);

let AppNav = StackNavigator({
    Home: {
        screen: HomeScene,
        navigationOptions: ({navigation}) => ({
            header: (
                <Toolbar
                    navigation={navigation}
                    needBack={false}//是不是需要返回按钮
                    text={''}/>//title内容
            ),
        }),
    },
    Video: {
        screen: VideoScene,
        navigationOptions: ({navigation}) => ({
            header: (
                <Toolbar
                    navigation={navigation}
                    backgroundColor={'rgba(0,0,0,0)'}
                    needBack={true}/>//是不是需要返回按钮
            ),
        }),
    },

    Login: {
        screen: LoginScene,
        navigationOptions: ({navigation}) => ({
            header: (
                <View/>
            ),
            title: '登陆',

        }),
    },
    Register: {
        screen: RegisterScene,
        navigationOptions: ({navigation}) => ({
            header: (
                <Toolbar
                    navigation={navigation}
                    needBack={false}//是不是需要返回按钮
                    text={'用户注册'}/>//title内容
            ),
        }),
    },
    AboutUs: {
        screen: AboutUsScene,
        navigationOptions: ({navigation}) => ({
            header: (
                <Toolbar
                    navigation={navigation}
                    backgroundColor={'#00F'}
                    needBack={true}
                    textColor={'#FFF'}//title颜色
                    text={'关于我们'}/>//title内容
            ),
        }),
    },
    ResetPwd: {
        screen: ResetPwdScene,
        navigationOptions: ({navigation}) => ({
            header: (
                <Toolbar
                    navigation={navigation}
                    backgroundColor={'#00F'}
                    needBack={true}
                    textColor={'#FFF'}//title颜色
                    text={'修改密码'}/>//title内容
            ),
        }),
    },
    ForgetPwd: {
        screen: ForgetPwdScene,
        navigationOptions: ({navigation}) => ({
            header: (
                <Toolbar
                    navigation={navigation}
                    backgroundColor={'#00F'}
                    needBack={true}
                    textColor={'#FFF'}//title颜色
                    text={'忘记密码'}/>//title内容
            ),
        }),
    },
    UserInfo: {
        screen: UserInfoScene,
        navigationOptions: ({navigation}) => ({
            header: (
                <Toolbar
                    navigation={navigation}
                    needBack={true}
                    backgroundColor={'#00F'}
                    needBack={true}
                    textColor={'#FFF'}//title颜色
                    text={'个人信息'}/>//title内容
            ),
        }),
    },

}, {
    initialRouteParams: {
        title: '',
        someDate: '',

    },
    initialRouteName: initialRouteName,
    headerMode: 'screen' // <-- should allow you to change the styles of the header
})

const styles = StyleSheet.create({
    headerStyle: {
        height: 0,
        backgroundColor: '#32CD32',
        elevation: 0, //remove shadow on Android
        shadowOpacity: 0, //remove shadow on iOS

    }
})
module.exports = AppNav;